/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.lm.base.util;

import br.com.lm.filter.Configuracao;
import java.io.Serializable;
import java.util.Map;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * @author Robson
 */
public class ListenerContextoEM implements ServletContextListener, Serializable {

    private static final long serialVersionUID = 1L;

    private static Map<String, Map> tabelaConfiguracao;   

    @Override
    @SuppressWarnings("CallToThreadDumpStack")
    public void contextInitialized(ServletContextEvent ev) {
        try {
            JPAUtil.carregarFabrica();
        } catch (Exception e) {
            System.out.println("Erro na carregamento da fabrica do JPA - " + e.getMessage());
        }
        
        try {
            Configuracao configuracao = new Configuracao();
            configuracao.gravaObjeto();
            tabelaConfiguracao = configuracao.tabelasMap;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("Erro ao carregar tabela de configuração do Sistema: " + e.getMessage());
        }        
    }

    @Override
    public void contextDestroyed(ServletContextEvent ev) {
        JPAUtil.destruirFabrica();
    }
        
    public static Map<String, Map> getTabelaConfiguracao() {
        return tabelaConfiguracao;
    } 
    
}